/*

package com.itheima.controller;

import com.itheima.pojo.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequestMapping("/consumer")
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    //服务拉取
    @Autowired
    private DiscoveryClient discoveryClient;

    @HystrixCommand(fallbackMethod = "queryByIdCallBack")
    @GetMapping("/{id}")
    public String queryById(@PathVariable("id") Long id) {
*/
/*
        //获取服务端实例化对象
        List<ServiceInstance> userService = discoveryClient.getInstances("user_service");
        ServiceInstance serviceInstance = userService.get(0);
        String host = serviceInstance.getHost();
        int port = serviceInstance.getPort();
        String url = String.format("http://%s:%s/user/%s", serviceInstance.getHost(), serviceInstance.getPort(), id);
        //String url="http:"+host+":"+port+"/user/"+id;
        // 调用RestTemplate的getForObject方法，指定url地址和返回值类型
        //将json转为object对象
        User user = restTemplate.getForObject(url, User.class);
        return user;*//*


        String url = "http://user-service/user/" + id;
        if (id == 1) {
            throw new RuntimeException("太忙了");
        }
        String user = restTemplate.getForObject(url, String.class);
        return user;
    }
    public String queryByIdCallBack(Long id) {
        return "服务不可用，请稍后重试！！！";
    }
}
*/
